package com.lex.jfb;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2016/5/23.
 */
public class YouHuiQ_XQActivity extends AppCompatActivity{
    private ListView recordListView;

    public static final String KEY_COUPON_VALUE="name_1";
    public static final String KEY_COUPON_NAME="name_2";
    public static final String KEY_COUPON_RULE="name_3";
    public static final String KEY_COUPON_VALUE_TIME="name_4";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tianchongliebiao);
        findView();
        initView();
    }
    private void findView(){
        recordListView = (ListView) findViewById(R.id.integral_record_1);
    }
    private void initView(){
        final List<Map<String,String>>data = new ArrayList<>();
        for (int i = 0;i < 10; i++){
            Map<String,String>map = new HashMap<>();
            map.put(KEY_COUPON_VALUE," "+(10+i));
            map.put(KEY_COUPON_NAME,"新店沙拉套餐优惠券");
            map.put(KEY_COUPON_RULE,"满"+(10+i)+"元可用");
            map.put(KEY_COUPON_VALUE_TIME,"有效期 2015/3/25 至 2016/3/25");
            data.add(map);
        }
        SimpleAdapter recordAdapter = new SimpleAdapter(this,data,R.layout.activity_youhuiquan_liebiao,
                new String[]{KEY_COUPON_VALUE,KEY_COUPON_NAME,KEY_COUPON_RULE,KEY_COUPON_VALUE_TIME},
                new int[]{R.id.coupon_value,R.id.coupon_name,R.id.coupon_rule, R.id.coupon_valid_time});
        recordListView.setAdapter(recordAdapter);

        recordListView.setOnItemClickListener(new AdapterView.OnItemClickListener(){
            public void onItemClick(AdapterView<?>parent,View view,int position,long id){
                Intent intent = new Intent(YouHuiQ_XQActivity.this,ShiYong_YHQActivity.class);
                Map<String,String> clickedMap = data.get(position);
                intent.putExtra(KEY_COUPON_VALUE,clickedMap.get(KEY_COUPON_VALUE));
                intent.putExtra(KEY_COUPON_NAME,clickedMap.get(KEY_COUPON_NAME));
                intent.putExtra(KEY_COUPON_RULE,clickedMap.get(KEY_COUPON_RULE));
                intent.putExtra(KEY_COUPON_VALUE_TIME,clickedMap.get(KEY_COUPON_VALUE_TIME));
                startActivity(intent);
            }
        });
    }

}
